//a = 76543, b = 4
//a = 1, b = 0
//a = 9, b = 15
a = 17, b = 1
function solution(a, b) {
    let str = a.toString()
    let str2 = b.toString()
    let len = str.length
    let result = ''
    let flag = true
    for (let i = 0; i < len; i++) {
        if (parseInt(str2[0]) > parseInt(str[i]) && flag) {
            result = result + b
            flag = false
        }
        result += str[i]
        //console.log(result);
    }
    if (flag) {
        result += b
    }
    return parseInt(result)
}

// function solution(a, b) {
//     let min = 0
// }

console.log(solution(a, b));
